package com.github.edu.manager.fwdl.controller;

import com.github.admin.edu.assembly.common.entity.JsonArray;
import com.github.admin.edu.assembly.page.entity.Pager;
import com.github.edu.client.common.annotation.*;
import com.github.edu.client.common.controller.BaseController;
import com.github.edu.manager.fwdl.service.LyqyService;
import com.github.edu.manager.fwdl.service.LyxxService;
import com.github.edu.repair.api.entity.TBxFwfl;
import com.github.edu.repair.api.entity.TBxLyqy;
import com.github.edu.repair.api.entity.TBxLyxx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Create by IntelliJ IDEA
 * 用户：王建
 * 日期：2018-8-22
 */
@Controller
@RequestMapping("/uc/lyxx")
public class LyxxController extends BaseController<TBxLyxx,Integer> {

    @Autowired
    private LyxxService service;

    @Autowired
    private LyqyService lyqyService;

    @ModelAttribute
    public void getQyxx(ModelMap map){
        List<TBxLyqy> lyqies=lyqyService.getAll();
        map.put("listLyqy",lyqies);
    }

    @QueryAll
    public String index(ModelMap modelMap, TBxLyxx sysOauth, Pager pager) {
        if(null==pager){
            pager=new Pager();
        }
        pager.setDirection("ASC");
        String[] strs={"id"};
        pager.setOrder(strs);
        JsonArray<TBxLyxx> jsonArray=service.getAllByPage(sysOauth,pager);
        return super.index(modelMap,sysOauth,jsonArray,"lyxx","楼宇信息",
                "编码:id","楼层名称:lymc","说明:sm","所属区域:ssqymc","当前状态:stateName");
    }

    @New
    public String add(ModelMap modelMap, TBxLyxx sysOauth, HttpServletRequest request) {
        return super.newIndex(modelMap,sysOauth,"lyxx","保存楼宇信息");
    }

    @Save
    public String saveOrUpdate(ModelMap modelMap, TBxLyxx sysOauth, HttpServletRequest request) {
        sysOauth=service.saveOrUpdate(sysOauth);
        return super.saveObject(modelMap,sysOauth,"保存成功！","lyxx","保存楼宇信息");
    }

    @Open
    public String openEntity(ModelMap modelMap,@PathVariable("id") Integer id) {
        TBxLyxx application=service.getEntity(id);
        return super.openEntity(modelMap,application,"lyxx","查看详情");
    }
    @Edit
    public String edit(ModelMap modelMap,@PathVariable("id") Integer s) {
        TBxLyxx application=service.getEntity(s);
        return super.newIndex(modelMap,application,"lyxx","修改楼宇信息");
    }

    @Delete
    public String delete( String ids) {
        return service.delete(ids);
    }

}
